home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso / shareware / telecom / term_4.1 / extras / hydracom / source / misc.c < prev    next >
C/C++ Source or Header  |  1994-11-17  |  18KB  |  658 lines

  1. /*=============================================================================
  2.  
  3.                               HydraCom Version 1.00
  4.  
  5.                          A sample implementation of the
  6.                    HYDRA Bi-Directional File Transfer Protocol
  7.  
  8.                              HydraCom was written by
  9.                    Arjen G. Lentz, LENTZ SOFTWARE-DEVELOPMENT
  10.                   COPYRIGHT (C) 1991-1993; ALL RIGHTS RESERVED
  11.  
  12.                        The HYDRA protocol was designed by
  13.                  Arjen G. Lentz, LENTZ SOFTWARE-DEVELOPMENT and
  14.                              Joaquim H. Homrighausen
  15.                   COPYRIGHT (C) 1991-1993; ALL RIGHTS RESERVED
  16.  
  17.  
  18.   Revision history:
  19.   06 Sep 1991 - (AGL) First tryout
  20.   .. ... .... - Internal development
  21.   11 Jan 1993 - HydraCom version 1.00, Hydra revision 001 (01 Dec 1992)
  22.  
  23.  
  24.   For complete details of the Hydra and HydraCom licensing restrictions,
  25.   please refer to the license agreements which are published in their entirety
  26.   in HYDRACOM.C and LICENSE.DOC, and also contained in the documentation file
  27.   HYDRACOM.DOC
  28.  
  29.   Use of this file is subject to the restrictions contained in the Hydra and
  30.   HydraCom licensing agreements. If you do not find the text of this agreement
  31.   in any of the aforementioned files, or if you do not have these files, you
  32.   should immediately contact LENTZ SOFTWARE-DEVELOPMENT and/or Joaquim
  33.   Homrighausen at one of the addresses listed below. In no event should you
  34.   proceed to use this file without having accepted the terms of the Hydra and
  35.   HydraCom licensing agreements, or such other agreement as you are able to
  36.   reach with LENTZ SOFTWARE-DEVELOMENT and Joaquim Homrighausen.
  37.  
  38.  
  39.   Hydra protocol design and HydraCom driver:         Hydra protocol design:
  40.   Arjen G. Lentz                                     Joaquim H. Homrighausen
  41.   LENTZ SOFTWARE-DEVELOPMENT                         389, route d'Arlon
  42.   Langegracht 7B                                     L-8011 Strassen
  43.   3811 BT  Amersfoort                                Luxembourg
  44.   The Netherlands
  45.   FidoNet 2:283/512, AINEX-BBS +31-33-633916         FidoNet 2:270/17
  46.   arjen_lentz@f512.n283.z2.fidonet.org               joho@ae.lu
  47.  
  48.   Please feel free to contact us at any time to share your comments about our
  49.   software and/or licensing policies.
  50.  
  51. =============================================================================*/
  52.  
  53. #include "hydracom.h"
  54.  
  55. #ifdef AMIGA
  56. #include <dos/dosextens.h>
  57. #include <clib/dos_protos.h>
  58. #endif    /* AMIGA */
  59.  
  60. static char *chatstart = "\007\007 * Chat mode start\r\n";
  61. static char *chatend   = "\007\007\r\n * Chat mode end\r\n";
  62. static char *chattime  = "\007\007\r\n * Chat mode end - timeout\r\n";
  63.  
  64.  
  65. static void loc_puts (char *s)
  66. {
  67. #ifdef AMIGA
  68.     ConPrintf(LocalRequest,s);
  69. #else
  70.         while (*s) {
  71.               if (*s == '\007')
  72. #if WIN_AGL
  73.                  (void) win_bell();
  74. #else
  75.                  putc(7,stderr);
  76. #endif
  77.               else
  78. #if WIN_AGL
  79.                  win_putc(local_win,*s);
  80. #else
  81.                  putch(*s);
  82. #endif
  83.               s++;
  84.         }
  85. #endif    /* AMIGA */
  86. }/*loc_puts()*/
  87.  
  88.  
  89. int keyabort (void)
  90. {
  91. #define CHATLEN 256
  92.         static byte     chatbuf1[CHATLEN + 5],
  93.                         chatbuf2[CHATLEN + 5],
  94.                        *curbuf = chatbuf1;
  95.         static boolean  warned = false;
  96.         boolean         esc = false;
  97.         char           *p;
  98.         word            c;
  99.  
  100.         if (chattimer > 0L) {
  101.            if (time(NULL) > chattimer) {
  102.               chattimer = lasttimer = 0L;
  103.               hydra_devsend("CON",(byte *) chattime,strlen(chattime));
  104.               loc_puts(&chattime[2]);
  105.            }
  106.            else if ((time(NULL) + 10L) > chattimer && !warned) {
  107.               loc_puts("\007\r\n * Warning: chat mode timeout in 10 seconds\r\n");
  108.               warned = true;
  109.            }
  110.         }
  111.         else if (chattimer != lasttimer) {
  112.            if (chattimer ==  0L) {
  113.               if (nobell) p = " * Remote has chat facility with bell disabled\n";
  114.               else        p = " * Remote has chat facility with bell enabled\n";
  115.               hydra_devsend("CON",(byte *) p,(int) strlen(p));
  116.               loc_puts(" * Hydra session in progress, chat facility now available\r\n");
  117.            }
  118.            else if (chattimer == -1L)
  119.               loc_puts(" * Hydra session in init state, can't chat yet\r\n");
  120.            else if (chattimer == -2L)
  121.               loc_puts(" * Remote has no chat facility available\r\n");
  122.            else if (chattimer == -3L) {
  123.               if (lasttimer > 0L) loc_puts("\r\n");
  124.               loc_puts(" * Hydra session in exit state, can't chat anymore\r\n");
  125.            }
  126.            lasttimer = chattimer;
  127.         }
  128.  
  129. #if WIN_AGL
  130.         while (win_keyscan()) {
  131. #else
  132. #ifdef AMIGA
  133.         while (ConScanKey()) {
  134. #else
  135.         while (kbhit()) {
  136. #endif
  137. #endif
  138.               switch (c = get_key()) {
  139.                      case Esc:
  140.                           esc = true;
  141.                           break;
  142.  
  143.                      case Alt_C:
  144.                           if (chattimer == 0L) {
  145.                              hydra_devsend("CON",(byte *) chatstart,strlen(chatstart));
  146.                              loc_puts(&chatstart[2]);
  147.                              chattimer = lasttimer = time(NULL) + CHAT_TIMEOUT;
  148.                           }
  149.                           else if (chattimer > 0L) {
  150.                              chattimer = lasttimer = 0L;
  151.                              hydra_devsend("CON",(byte *) chatend,strlen(chatend));
  152.                              loc_puts(&chatend[2]);
  153.                           }
  154.                           else
  155.                              loc_puts("\007");
  156.                           break;
  157.  
  158.                      default:
  159.                           if (c < ' ' || c > 126)
  160.                              break;
  161.  
  162.                      case '\r':
  163.                      case '\a':
  164.                      case '\b':
  165.                           if (chattimer <= 0L)
  166.                              break;
  167.  
  168.                           chattimer = time(NULL) + CHAT_TIMEOUT;
  169.                           warned = false;
  170.  
  171.                           if (chatfill >= CHATLEN)
  172.                              loc_puts("\007");
  173.                           else {
  174.                              switch (c) {
  175.                                     case '\r':
  176.                                          curbuf[chatfill++] = '\n';
  177.                                          loc_puts("\r\n");
  178.                                          break;
  179.  
  180.                                     case '\b':
  181.                                          if (chatfill > 0 && curbuf[chatfill - 1] != '\n')
  182.                                             chatfill--;
  183.                                          else {
  184.                                             curbuf[chatfill++] = '\b';
  185.                                             curbuf[chatfill++] = ' ';
  186.                                             curbuf[chatfill++] = '\b';
  187.                                          }
  188.                                          loc_puts("\b \b");
  189.                                          break;
  190.  
  191.                                     default:
  192.                                          curbuf[chatfill++] = (byte) c;
  193.                                          if (c != 7)
  194. #if WIN_AGL
  195.                                             win_putc(local_win,c);
  196. #else
  197. #ifdef AMIGA
  198.                                             ConPrintf(LocalRequest,"%lc",c);
  199. #else
  200.                                             putch(c);
  201. #endif
  202. #endif
  203.                                          break;
  204.                              }
  205.                           }
  206.                           break;
  207.               }
  208.         }
  209.  
  210.         if (chatfill > 0 && hydra_devsend("CON",curbuf,chatfill)) {
  211.            curbuf = (curbuf == chatbuf1) ? chatbuf2 : chatbuf2;
  212.            chatfill = 0;
  213.         }
  214.  
  215.         return (esc);
  216. }/*keyabort()*/
  217.  
  218.  
  219. void rem_chat (byte *data, word len)
  220. {
  221.         len = len;
  222.  
  223. #if !WIN_AGL && !defined(AMIGA)
  224.         local_x = wherex();
  225.         local_y = wherey();
  226.         window(1,11,80,17);
  227.         gotoxy(remote_x,remote_y);
  228. #endif
  229.  
  230.         while (*data) {
  231.               switch (*data) {
  232.